let arr = [3, 6, 9, 1, 2, 6]

function get(arr = []) {
    if (arr.length < 2) return;
    let m = 0;
    let isBuy = false;
    for (let i = 0; i < arr.length; i++) {
        if (i < arr.length - 1) {
            if (!isBuy && arr[i] < arr[i + 1]) {
                isBuy = true;
                m -= arr[i];
            }
        }
        if (isBuy && arr[i] > arr[i + 1]) {
            isBuy=false;
            m+=arr[i];
            m--;
        }
    }
    if(isBuy){
        m+=arr[arr.length-1];
        m--;
    }
    return m;
}
console.log(get(arr));
